Skip to content

Conversation

linzebing
Copy link
Contributor

@linzebing linzebing commented Jul 25, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

In engine core thread, we used 18us to convert EngineCoreRequest to Request which is on model forward critical path.

Ideally, we should be able to move the conversion from engine core thread to input request thread to relax the logic from critical path.

There's an extra benefit for making the change, as Request became available in input processing threads, which would significantly simply the pending changes for block hashing optimization mentioned in #21247

image image

Test Plan

export VLLM_USE_MODELSCOPE=False;
export VLLM_TORCH_PROFILER_DIR=~/vllm_profile; # for profiling
export CUDA_VISIBLE_DEVICES=4;
VLLM_USE_V1=1 vllm serve facebook/opt-125m \
    --swap-space 16 \
    --disable-log-requests \
    --host :: \
    --dtype float16
VLLM_USE_V1=1 vllm bench serve \
    --dataset-name random \
    --model facebook/opt-125m \
    --served-model-name facebook/opt-125m \
    --random-input-len 700 \
    --random-output-len 1 \
    --endpoint /v1/completions \
    --ignore-eos \
    --host localhost \
    --port 8000 \
    --num-prompts 100 \
    --profile

Test Result

With the change, handle_client_request in engine core thread reduced from 35us to 7us.
image

As expected, right now, Request conversion is executing in parallel with model forward:
Screenshot 2025-07-25 at 12 11 49 PM

(Optional) Documentation Update

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Jul 25, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively moves the EngineCoreRequest to Request conversion out of the engine's critical path, which, as shown by the profiling data, significantly improves performance. The implementation is clean and the logic is sound.

My main concern is about the robustness of the process_input_sockets thread. By moving more complex logic into this daemon thread, the risk of silent failures that could hang the server increases. I've added a high-severity comment with a suggestion to implement more robust error handling to ensure the engine fails gracefully.

@linzebing
Copy link
Contributor Author

@Jialin has generously delegated #21329 to me as my first PR to vLLM.

@njhill : I have addressed your comments and used a tuple to represent request and current_wave. Let me know if you have further comments

Comment on lines 803 to 811
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an additional protection? Or we do have such error handling originally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is additional protection, in response to gemini's review above #21627 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep the PR focused and not introduce new error handling here.

Copy link
Contributor

@Jialin Jialin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @linzebing this looks good to me for the most part!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this

Suggested change
def add_request(self, request: Request, current_wave: int = 0):
def add_request(self, request: Request, request_wave: int = 0):

Comment on lines 803 to 811
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep the PR focused and not introduce new error handling here.

@linzebing linzebing force-pushed the request branch 2 times, most recently from 67ee54e to fdca348 Compare July 29, 2025 00:19
@linzebing linzebing requested a review from njhill July 29, 2025 00:22
@linzebing linzebing force-pushed the request branch 2 times, most recently from c6732fe to 1698a9d Compare July 29, 2025 00:31
Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @linzebing @Jialin!

One more thing, do you think you could also add a short comment in the code next to each of those two things confirming that they are threadsafe?

@linzebing
Copy link
Contributor Author

Thanks @njhill for the review! I have added comments around thread safety.

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @linzebing!

@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 29, 2025
@njhill
Copy link
Member

njhill commented Jul 30, 2025

@linzebing I think some of the CI test failures are related: https://buildkite.com/vllm/ci/builds/25313#01985782-1b21-4082-9849-1642052665bc/212-1966

@linzebing
Copy link
Contributor Author

linzebing commented Jul 30, 2025

@njhill : thanks for pointing out! I forgot to examine the callsites of EngineCore::add_request in the tests. Now it should be fixed:

pytest tests/v1/engine/test_engine_core.py

I manually inspected the codebase, I should have changed all callsites of EngineCore::add_request now.

Copy link

mergify bot commented Jul 30, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @linzebing.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Jul 30, 2025
@linzebing
Copy link
Contributor Author

Looks like the v1-test failure is related to CI. I tested locally, no issue:

pytest tests/v1/kv_connector/unit/test_shared_storage_connector.py

@Jialin
Copy link
Contributor

Jialin commented Jul 30, 2025

Looks like the v1-test failure is related to CI. I tested locally, no issue:

pytest tests/v1/kv_connector/unit/test_shared_storage_connector.py

@linzebing If you confirmed the failing test is not related, you could either rebase to kick off the CI or request force merge in sig-ci slack channel.

@simon-mo simon-mo merged commit ca9e2be into vllm-project:main Jul 30, 2025
64 of 66 checks passed
liuyumoye pushed a commit to liuyumoye/vllm that referenced this pull request Jul 31, 2025
vadiklyutiy pushed a commit to CentML/vllm that referenced this pull request Aug 5, 2025
x22x22 pushed a commit to x22x22/vllm that referenced this pull request Aug 5, 2025
npanpaliya pushed a commit to odh-on-pz/vllm-upstream that referenced this pull request Aug 6, 2025
jinzhen-lin pushed a commit to jinzhen-lin/vllm that referenced this pull request Aug 9, 2025
noamgat pushed a commit to noamgat/vllm that referenced this pull request Aug 9, 2025
paulpak58 pushed a commit to paulpak58/vllm that referenced this pull request Aug 13, 2025
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants